package day_7_16;

import java.util.HashMap;
import java.util.Map;

public class Main1 {
    /**
     * 205. 同构字符串
     * https://leetcode.cn/problems/isomorphic-strings/description/?envType=study-plan-v2&envId=top-interview-150
     */
    public boolean isIsomorphic(String s, String t) {
        Map<Character,Character> s2t = new HashMap<>();
        Map<Character,Character> t2s = new HashMap<>();
        for(int i = 0;i < s.length();i++) {
            char a = s.charAt(i);
            char b = t.charAt(i);
            // 存放的映射关系
            if(s2t.containsKey(a) && s2t.get(a) != b ||
                    t2s.containsKey(b) && t2s.get(b) != a) {
                return false;
            }
            s2t.put(a,b);
            t2s.put(b,a);
        }
        return true;
    }
}
